﻿using System;
using System.Threading;

namespace csharpbiancheng_ch14_Thread_Abort_example
{
    class Program
    {

        private static int count = 10;
        private static void GiveRedEnvelop()
        {
            while (count > 0)
            {
                count--;
                if (count == 4)
                {
                    //终止当前线程
                    Console.WriteLine("红包暂停发放!");
                    //Thread.CurrentThread.Abort();//不支持net3.0不支持                 
                  
                }
                Console.WriteLine("剩余 {0} 个红包",count);
            }
        }
        static void Main(string[] args)
        {
            ThreadStart ts = new ThreadStart(GiveRedEnvelop);           
            Thread t = new Thread(ts);
            t.IsBackground = true;
            t.Start();         
            if (t.IsBackground == false)
            {
                Console.WriteLine("该线程不是后台线程!");
                t.IsBackground = true;
            }
            else
            {
                Console.WriteLine("该线程是后台线程!");               
            }            
        }
    }
}
